<%--
  Created by IntelliJ IDEA.
  User: cos
  Date: 2021/11/17
  Time: 9:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

</head>
<body>
<div id="msg"></div>
<hr>
<button id="btn1">按钮1</button>
<button id="btn2">按钮2</button>
<button id="btn3">按钮3</button>
<button id="btn4">按钮4</button>
<button id="btn5">按钮5</button>

<script>
    $(function () {
        $("#btn1").click(function () {
            /* get */
            $.get("/user/getUserByUno", "uno=" + 1, function (result) {
                $("#msg").text(result.uname);
            });
        });
        $("#btn2").click(function () {
            /* post */
            $.post("/user/getUserByUno?uno=" + 1, function (result) {
                $("#msg").text(result.uno + "--" + result.uname);
            })
        });
        $("#btn3").click(function () {
            /* post */
            $.ajax({
                url: "/user/getUserByUno",
                type: "get",
                data: "uno=" + 1,
                success: function (result) {
                    $("#msg").text(result.uno + "--" + result.uname);
                }
            })
        })
        $("#btn4").click(function () {
            /* post */
            var u = {uno:1,uname:"王五",usex:"女",bornDate:"2020-9-9"};
            //当我们发送json数据的时候,提交方式必须为post
            $.ajax({
                url: "/user/add",
                type: "post",
                data: JSON.stringify(u),//要发送的数据
                contentType:"application/json",//设置发送数据的类型是什么,不设置就是默认的xxx-www即菩提的表单提交方式,key=value
                success: function (result) {
                    $("#msg").text(result);
                }
            })
        })
        $("#btn5").click(function () {
            /* post */
            var u = {uno:1,uname:"王五",usex:"女",bornDate:"2020-9-9"};
            //当我们发送json数据的时候,提交方式必须为post
            $.ajax({
                url: "/user/getAll",
                type: "get",
                dataType:"text",//自动转为json字符串
                success: function (result) {
                    $("#msg").text(result);
                }
            })
        })
    })
</script>

</body>
</html>
